package org.osomit.sacct.session.token.impl;

import org.osomit.sacct.session.token.iface.TokenExpirationPolicy;
import org.osomit.sacct.session.token.iface.TokenState;

/**
 * @author Jian Fang (John.Jian.Fang@gmail.com)
 *
 * Date: Jul 1, 2009
 */
public class CountUsedTokenExpirationPolicy implements TokenExpirationPolicy {
    private static final long serialVersionUID = 644101842530862839L;
    
    //The count used that the token can live
    private final long countOfUsedAllowed;

    public CountUsedTokenExpirationPolicy(long countOfUsedAllowed) {
        this.countOfUsedAllowed = countOfUsedAllowed;
    }

    public long getCountOfUsedAllowed() {
        return this.countOfUsedAllowed;
    }

    public boolean isExpired(TokenState tokenState) {
       return (tokenState == null) || (tokenState.getCountUsed() >= this.countOfUsedAllowed);
    }
}
